From e4de412fd34a489a712a5f223c7824d3aba99136 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 12 Sep 2015 19:50:42 -0400 Subject: [PATCH] Move widget paths to gdata We only use widget paths for a few widgets nowadays (notebook, treeview, pathbar, combobox), so we can save some space by not having this field in GtkWidgetPrivate. --- gtk/gtkwidget.c | 37 ++++++++++++++++++++----------------- gtk/gtkwidgetprivate.h | 8 +++----- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 1acbf6ec63..acb3822390 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -860,6 +860,7 @@ static GQuark quark_modifier_style = 0; static GQuark quark_enabled_devices = 0; static GQuark quark_size_groups = 0; static GQuark quark_auto_children = 0; +static GQuark quark_widget_path = 0; GParamSpecPool *_gtk_widget_child_property_pool = NULL; GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL; @@ -1027,6 +1028,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices"); quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups"); quark_auto_children = g_quark_from_static_string ("gtk-widget-auto-children"); + quark_widget_path = g_quark_from_static_string ("gtk-widget-path"); style_property_spec_pool = g_param_spec_pool_new (FALSE); _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE); @@ -11948,19 +11950,16 @@ static void gtk_widget_constructed (GObject *object) { GtkWidget *widget = GTK_WIDGET (object); - GtkWidgetPrivate *priv = widget->priv; + GtkWidgetPath *path; /* As strange as it may seem, this may happen on object construction. * init() implementations of parent types may eventually call this function, * each with its corresponding GType, which could leave a child * implementation with a wrong widget type in the widget path */ - if (priv->path && - G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path)) - { - gtk_widget_path_free (priv->path); - priv->path = NULL; - } + path = (GtkWidgetPath*)g_object_get_qdata (object, quark_widget_path); + if (path && G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (path)) + g_object_set_qdata (object, quark_widget_path, NULL); G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object); } @@ -12195,8 +12194,7 @@ gtk_widget_finalize (GObject *object) if (accessible) g_object_unref (accessible); - if (priv->path) - gtk_widget_path_free (priv->path); + gtk_widget_clear_path (widget); gtk_css_widget_node_widget_destroyed (GTK_CSS_WIDGET_NODE (priv->cssnode)); g_object_unref (priv->cssnode); @@ -16380,22 +16378,27 @@ _gtk_widget_create_path (GtkWidget *widget) GtkWidgetPath * gtk_widget_get_path (GtkWidget *widget) { + GtkWidgetPath *path; + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - if (!widget->priv->path) - widget->priv->path = _gtk_widget_create_path (widget); + path = (GtkWidgetPath*)g_object_get_qdata (G_OBJECT (widget), quark_widget_path); + if (!path) + { + path = _gtk_widget_create_path (widget); + g_object_set_qdata_full (G_OBJECT (widget), + quark_widget_path, + path, + (GDestroyNotify)gtk_widget_path_free); + } - return widget->priv->path; + return path; } void gtk_widget_clear_path (GtkWidget *widget) { - if (widget->priv->path) - { - gtk_widget_path_free (widget->priv->path); - widget->priv->path = NULL; - } + g_object_set_qdata (G_OBJECT (widget), quark_widget_path, NULL); } void diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index 7292aa8e07..42d741b1e9 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -120,8 +120,9 @@ struct _GtkWidgetPrivate /* The list of attached windows to this widget. * We keep a list in order to call reset_style to all of them, - * recursively. */ - GList *attached_windows; + * recursively. + */ + GList *attached_windows; /* The style for the widget. The style contains the * colors the widget should be drawn in for each state @@ -132,9 +133,6 @@ struct _GtkWidgetPrivate GtkCssNode *cssnode; GtkStyleContext *context; - /* Widget's path for styling */ - GtkWidgetPath *path; - /* The widget's allocated size */ GtkAllocation allocation; gint allocated_baseline; -- 2.30.2